﻿<Window x:Class="Seeker.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Seeker"
        xmlns:converters="clr-namespace:Seeker.Converters"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="Seeker" Height="450" Width="525" Icon="seeker.ico">
    <Window.Resources>
        <converters:FilenameConverter x:Key="FilenameConverter"/>
        <converters:PathConverter x:Key="FolderConverter"/>
    </Window.Resources>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="ActiveStates">
            <VisualState x:Name="Inactive"/>
            <VisualState x:Name="Active">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Cursor)" Storyboard.TargetName="LayoutRoot">
                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Cursors.AppStarting}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="panelIsBusy">
                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="panelInput">
                        <DiscreteObjectKeyFrame KeyTime="0:0:0">
                            <DiscreteObjectKeyFrame.Value>
                                <sys:Boolean>False</sys:Boolean>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid x:Name="panelInput">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="Named:" Margin="10,5,0,5" VerticalAlignment="Center"/>
            <Grid Grid.Column="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBox x:Name="textNamed" Text="{Binding SearchPattern, Mode=TwoWay}" VerticalAlignment="Center" Margin="10,5,10,5"/>

                <Grid Grid.Column="1" Margin="0,0,10,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Button x:Name="buttonSearch" Grid.Column="0" Content="Search" Command="{Binding SearchCommand, Mode=OneWay}" HorizontalAlignment="Stretch" Margin="0,5,5,5" Padding="15,5,15,5"/>
                    <Button x:Name="buttonReplace" Grid.Column="1" Content="Replace" Command="{Binding ReplaceCommand, Mode=OneWay}" HorizontalAlignment="Stretch" Margin="5,5,0,5" Padding="15,5,15,5"/>
                </Grid>
            </Grid>
            <TextBlock Grid.Row="1" Text="Folder:" Margin="10,5,0,5" VerticalAlignment="Center"/>
            <Grid Grid.Row="1" Grid.Column="1" Margin="0,0,10,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBox x:Name="textFolder" Text="{Binding Path, Mode=TwoWay}" VerticalAlignment="Center" Margin="10,5,10,5"/>
                <Button x:Name="buttonBrowse" Content="..." Grid.Column="2" Margin="0,5,0,5" Padding="10,5,10,5" Click="ButtonBrowse_Click"/>
            </Grid>
            <StackPanel Grid.Row="2" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="10,5,10,5">
                <TextBlock Text="Formatting:" VerticalAlignment="Center" Margin="0,5,10,5"/>
                <ComboBox x:Name="comboBoxFormatting" ItemsSource="{Binding AvailableEncodings, Mode=OneWay}" SelectedItem="{Binding SelectedEncoding, Mode=TwoWay}" VerticalAlignment="Center" MinWidth="100" Margin="0,0,10,0"/>
                <CheckBox x:Name="checkBoxMatchCase" Content="Match Case" IsChecked="{Binding MatchCase, Mode=TwoWay}" VerticalAlignment="Center" Margin="0,5,10,5"/>
                <CheckBox x:Name="checkBoxRegularExpression" Content="Use Regular Expressions" IsChecked="{Binding UseRegularExpressions, Mode=TwoWay}" VerticalAlignment="Center" Margin="0,5,10,5"/>
            </StackPanel>

            <StackPanel Grid.Row="4" Grid.ColumnSpan="2" Margin="10,0,10,0">
                <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                    <TextBlock Text="Search For:" VerticalAlignment="Center" Margin="0,0,12,0"/>
                    <CheckBox x:Name="checkBoxRunMultiple" Grid.Column="1" Content="Mutliple values (use new line for each)" IsChecked="{Binding MultipleValues, Mode=TwoWay}" VerticalAlignment="Center" Margin="0,0,10,0"/>
                </StackPanel>
                <TextBox x:Name="textBoxSearch" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" MinLines="3" Text="{Binding SearchFor, Mode=TwoWay}" Margin="0,5,0,5"/>
            </StackPanel>

            <StackPanel Grid.Row="5" Grid.ColumnSpan="2" Margin="10,0,10,0">
                <TextBlock Text="Replace With:" Margin="0,5,0,0"/>
                <TextBox x:Name="textBoxReplace" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" MinLines="3" Text="{Binding ReplaceWith, Mode=TwoWay}" Margin="0,5,0,5"/>
            </StackPanel>
        </Grid>

        <Grid x:Name="panelIsBusy" Visibility="Collapsed">
            <Border Background="#BB000000" VerticalAlignment="Center">
                <StackPanel Orientation="Vertical" Margin="0,20,0,20">
                    <TextBlock Text="{Binding ActiveFile, Mode=OneWay}" TextTrimming="CharacterEllipsis" TextAlignment="Center" Margin="10,0,10,10" Foreground="White"/>
                    <Button Content="Cancel" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="15,5,15,5" Command="{Binding CancelCommand, Mode=OneWay}"/>
                </StackPanel>
            </Border>
        </Grid>

        <ListView x:Name="listViewResults" Grid.Row="1" ItemsSource="{Binding SearchResults, Mode=OneWay}" SelectionMode="Single" Margin="10,5,10,10">
            <ListView.View>
                <GridView>
                    <GridView.Columns>
                        <GridViewColumn Header="File" DisplayMemberBinding="{Binding File, Converter={StaticResource FilenameConverter}, Mode=OneWay}"/>
                        <GridViewColumn Header="Path" DisplayMemberBinding="{Binding File, Converter={StaticResource FolderConverter}, Mode=OneWay}"/>
                        <GridViewColumn Header="Occurrences" DisplayMemberBinding="{Binding Occurrences, Mode=OneWay}"/>
                    </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>
        
        <StatusBar Grid.Row="2">
            <StatusBarItem>
                <TextBlock>
                    <TextBlock.Inlines>
                        <Run Text="Files: "/>
                        <Run Text="{Binding SearchResults.Count, Mode=OneWay, FallbackValue='0'}"/>
                    </TextBlock.Inlines>
                </TextBlock>
            </StatusBarItem>
            <StatusBarItem>
                <TextBlock>
                    <TextBlock.Inlines>
                        <Run Text="Occurrences: "/>
                        <Run Text="{Binding TotalOccurrences, Mode=OneWay}"/>
                    </TextBlock.Inlines>
                </TextBlock>
            </StatusBarItem>
        </StatusBar>

    </Grid>
</Window>
